package com.earnings.okhttputils.utils.car.ui;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.earnings.R;
import com.earnings.okhttputils.utils.car.adapter.CalculatorAdapter;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.god.Listener.GodOnClickListener;
import com.earnings.okhttputils.utils.utils.PagerSlidingTabStripUtils;
import com.earnings.okhttputils.utils.view.PagerSlidingTabStrip;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/6/20 0020.
 */

public class CalculatorActivity extends GodLeftHandBaseActivity implements PagerSlidingTabStrip.OnPagerTitleItemClickListener, ViewPager.OnPageChangeListener, GodOnClickListener {
    private PagerSlidingTabStrip pagerslidingtabstrip;
    private ViewPager viewpager;
    private TotalFragment totalFragment;
    private LoanFragment loanFragment;
    private CalculatorAdapter adapter;
    private String price,name;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_calculator;
    }

    @Override
    protected void init() {
        setHideTopView();
        price = getIntent().getStringExtra("price");
        name = getIntent().getStringExtra("name");
        pagerslidingtabstrip = getView(R.id.pagerslidingtabstrip);
        viewpager = getView(R.id.viewpager);
        totalFragment = new TotalFragment();
        loanFragment = new LoanFragment();
        totalFragment.setTitle("全款");
        loanFragment.setTitle("贷款");

        totalFragment.setPrice(price,name);
        loanFragment.setPrice(price,name);

        ArrayList arrayList = new ArrayList<Fragment>();
        arrayList.add(totalFragment);
        arrayList.add(loanFragment);
        adapter = new CalculatorAdapter(getSupportFragmentManager(), arrayList);
        viewpager.setAdapter(adapter);
        pagerslidingtabstrip.setViewPager(viewpager);
        PagerSlidingTabStripUtils.Cal(pagerslidingtabstrip, this);
        pagerslidingtabstrip.setOnPagerTitleItemClickListener(this);
        viewpager.addOnPageChangeListener(this);
        setOnClickListener(this,R.id.back);
    }


    @Override
    public void onSingleClickItem(int position) {
        viewpager.setCurrentItem(position);
    }

    @Override
    public void onDoubleClickItem(int position) {

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void OnClickListener(View view) {
        finish();
    }
}
